﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HotelProject
{
    public partial class AdvancedSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownItemGenerator.populateHotelsInDropDown(hotelSelection);
                DropDownItemGenerator.populateViewsDropDown(viewDropDown);
                DropDownItemGenerator.populateBedSizesInDropDownBox(bedSizeDropDown);
                DropDownItemGenerator.populatePricesInDropDownBox(maxPriceDropDownList);
                DropDownItemGenerator.populatePricesInDropDownBox(minPriceDropDownList);
                DropDownItemGenerator.populateFloorNumbersInDropDownBox(floorNumberDropDownList);
                DropDownItemGenerator.populateRoomNumbersInDropDownBox(roomNumberDropDownList);
            }
        }

       

        protected void Submit_Click(object sender, EventArgs e)
        {
            DateTime checkInDate, checkOutDate;
            DateTime.TryParse(txtDate1.Text, out checkInDate);
            DateTime.TryParse(txtDate2.Text, out checkOutDate);

            int minPrice, maxPrice, roomNumber, floorNumber;

            int.TryParse(minPriceDropDownList.SelectedValue, out minPrice);
            int.TryParse(maxPriceDropDownList.SelectedValue, out maxPrice);
            int.TryParse(roomNumberDropDownList.SelectedValue, out roomNumber);
            int.TryParse(floorNumberDropDownList.SelectedValue, out floorNumber);

            HotelSearchQuery searchQuery = new HotelSearchQuery()
            {
                hotelID = int.Parse(hotelSelection.SelectedValue),
                checkInDate = checkInDate,
                checkOutDate = checkOutDate,
                minPrice = minPrice,
                maxPrice = maxPrice,
                bedSize = bedSizeDropDown.SelectedValue,
                view = viewDropDown.SelectedValue,
                roomNumber = roomNumber,
                floorNumber = floorNumber

            };

            Session["searchQuery"] = searchQuery;

            Response.Redirect("Results.aspx");

        }
    }
}